package com.example.attack.listener;

import com.example.attack.model.ElCharacter;
import com.example.attack.utils.Event;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionalEventListener;

@Component
public class AttackListener {

    @TransactionalEventListener(fallbackExecution = true, condition = "#event.event.equalsCode(T(com.example.attack.listener.enums.AttackListenerEnum).COMMON_ATTACK)")
    public void handleCommonAttack(Event event){
        ElCharacter elCharacter = (ElCharacter) event.data;
        System.out.println(elCharacter.getName() + "受到了普通攻击");
    }

    @TransactionalEventListener(fallbackExecution = true, condition = "#event.event.equalsCode(T(com.example.attack.listener.enums.AttackListenerEnum).PHYSICAL_ATTACK)")
    public void handlePhysicalAttack(Event event){
        ElCharacter elCharacter = (ElCharacter) event.data;
        System.out.println(elCharacter.getName() + "受到了物理攻击");
    }

}
